/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */

var isValidBST = function (root) {
    return fn(root, -Infinity, Infinity)
    function fn(root, low, high) {
        if (!root) {
            return true
        }
        if (root.val <= low || root.val >= high) {
            return false;
        }
        return fn(root.left, low, root.val) && fn(root.right, root.val, high);
    }
};